package com.sanuo.pico.event;

public abstract class MaxMinEvent extends Co2IntEvent {

    public abstract int getMax();

    public abstract int getMin();

    public int getStep() {
        return 1;
    }

    @Override
    public boolean postValue(Integer value) {
        value = Math.min(value, getMax());
        value = Math.max(value, getMin());
        return super.postValue(value);
    }

    @Override
    public Integer getValue() {
        int value = super.getValue();
        value = Math.min(value, getMax());
        value = Math.max(value, getMin());
        return value;
    }

    public int forward() {
        int i = getValue() + getStep();
        postValue(i);
        return getValue();
    }

    public int backward() {
        int i = getValue() - getStep();
        postValue(i);
        return getValue();
    }
}
